﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Specialized;
namespace Piao
{

    public partial class PassengerInfoForm : Form
    {
        string[] visibleColumns = { 
                               
                               "passenger_1_name",
                               "passenger_1_cardno",
                               "passenger_1_mobileno"
                               
                               };
        public PassengerInfoForm(List<UserData> lst)
        {
            InitializeComponent();

            view.DataSource = lst;


            for (int i = 0; i < view.Columns.Count; i++)
            {
                if (!visibleColumns.Contains(view.Columns[i].Name))
                {
                    view.Columns[i].Visible = false;
                }
                view.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            }

#if DEBUG
            this.view.RowHeadersVisible = true;
#else
            this.view.RowHeadersVisible = false;
#endif


        }


        private void view_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                foreach (DataGridViewRow row in view.SelectedRows)
                {
                    foreach (string id in visibleColumns)
                    {
                        row.Cells[id].Value = string.Empty;
                    }
                }
            }
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            var lst = this.view.DataSource as List<UserData>;

            StringCollection strs = new StringCollection();
            foreach (UserData u in lst)
            {
                if (!string.IsNullOrEmpty(u.passenger_1_name) && !string.IsNullOrEmpty(u.passenger_1_cardno))
                    strs.Add(string.Join(",", new string[] { u.passenger_1_name, u.passenger_1_cardno, u.passenger_1_mobileno }));
            }

            Configurations.Instance.PassengerList = strs;
            Configurations.Instance.Save();

        }

    }
}
